package com.cmcc.xdr.message;

import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.cmcc.xdr.entity.PccEntity;

public class SingleSigPccMsg extends SingleSigMsg {

	public PccEntity pcc = new PccEntity();
	private static SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

	public SingleSigPccMsg(ByteBuffer buffer,SingleSigGlobalMsg globalMsg) {
		this.setBuffer(buffer);
		this.setSSGMsg(globalMsg);

		pcc.setLength(globalMsg.getTotalLength());
//		pcc.setCity(globalMsg.getCity());
		pcc.setLocalProvince(globalMsg.getLocalProvince());
		pcc.setLocalCity(globalMsg.getLocalCity());
		pcc.setOwnerProvince(globalMsg.getOwnerProvince());
		pcc.setOwnerCity(globalMsg.getOwnerCity());
		pcc.setRoamingType(globalMsg.getRoamingType());
		
		pcc.setInterFace(globalMsg.getInterfaceType());
		pcc.setXdrId(globalMsg.getXdrID());
		pcc.setRat(globalMsg.getRat());
		pcc.setImsi(globalMsg.getImsi());
		pcc.setImei(globalMsg.getImei());
		pcc.setMsisdn(globalMsg.getMsisdn());

		pcc.setProcedureType(loadInt(1));
		pcc.setProcedureStartTime(new Date(loadLong(8)));
		pcc.setProcedureEndTime(new Date(loadLong(8)));
		pcc.setIcid(loadStr(64));
		pcc.setOriginRealm(loadStr(44));
		pcc.setDestinationRealm(loadStr(44));
		pcc.setOriginHost(loadStr(64));
		pcc.setDestinationHost(loadStr(64));
		pcc.setSgsnSgwSigIP(loadIp(16));
		pcc.setAfAppID(loadStr(16));
		pcc.setCcRequestType(loadInt(1));
		pcc.setRxRequestType(loadInt(1));
//		pcc.setMediaType(loadInt(4));
		pcc.setMediaType(loadInt(1));//之前的长度为4
		pcc.setAbortCause(loadInt(1));
		pcc.setResultCode(loadInt(4));
		pcc.setExperimentalResultCode(loadInt(4));
		pcc.setSessionReleaseCause(loadInt(4));

    	pcc.setRuleFailureCode(loadInt(1));
		pcc.setSessionId(loadStr(128));//新增字段
		pcc.setIpv6Prefix(loadIp(16));//新增字段
    	pcc.setCalledStationId(loadInt(1));//新增字段
//    	pcc.setSessionId(loadStr(128));//新增字段//已删除
//    	pcc.setCalledStationId(loadStr(64));//新增字段//已删除
//    	pcc.setFramedIpv6Prefix(loadStr(16));//新增字段//已删除
//    	pcc.setFramedIpAddress(loadStr(4));//新增字段//已删除

		pcc.setInsertDate(format.format(new Date()));

		// dbtest.savePcc(pcc);
	}

	public PccEntity getPcc() {
		return pcc;
	}

	public void setPcc(PccEntity pcc) {
		this.pcc = pcc;
	}

}